package com.google.android.exoplayer2.scheduler;

import android.annotation.TargetApi;
import android.app.job.JobInfo;
import android.app.job.JobInfo.Builder;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Intent;
import android.os.PersistableBundle;
import o.ahz;
import o.anr;

@TargetApi(21)
public final class PlatformScheduler implements ahz {
    private final JobScheduler ˎ;
    private final int ˏ;
    private final ComponentName ॱ;

    public static final class PlatformSchedulerService extends JobService {
        public boolean onStartJob(JobParameters jobParameters) {
            PlatformScheduler.ˏ("PlatformSchedulerService started");
            PersistableBundle extras = jobParameters.getExtras();
            if (new Requirements(extras.getInt("requirements")).ॱ(this)) {
                PlatformScheduler.ˏ("Requirements are met");
                String string = extras.getString("service_action");
                String string2 = extras.getString("service_package");
                Intent intent = new Intent(string).setPackage(string2);
                PlatformScheduler.ˏ("Starting service action: " + string + " package: " + string2);
                anr.ˊ(this, intent);
            } else {
                PlatformScheduler.ˏ("Requirements are not met");
                jobFinished(jobParameters, true);
            }
            return false;
        }

        public boolean onStopJob(JobParameters jobParameters) {
            return false;
        }
    }

    public boolean ˏ(Requirements requirements, String str, String str2) {
        int schedule = this.ˎ.schedule(ˊ(this.ˏ, this.ॱ, requirements, str2, str));
        ˏ("Scheduling job: " + this.ˏ + " result: " + schedule);
        if (schedule == 1) {
            return true;
        }
        return false;
    }

    public boolean ˊ() {
        ˏ("Canceling job: " + this.ˏ);
        this.ˎ.cancel(this.ˏ);
        return true;
    }

    private static JobInfo ˊ(int i, ComponentName componentName, Requirements requirements, String str, String str2) {
        int i2;
        Builder builder = new Builder(i, componentName);
        switch (requirements.ˋ()) {
            case 0:
                i2 = 0;
                break;
            case 1:
                i2 = 1;
                break;
            case 2:
                i2 = 2;
                break;
            case 3:
                if (anr.ˋ >= 24) {
                    i2 = 3;
                    break;
                }
                throw new UnsupportedOperationException();
            case 4:
                if (anr.ˋ >= 26) {
                    i2 = 4;
                    break;
                }
                throw new UnsupportedOperationException();
            default:
                throw new UnsupportedOperationException();
        }
        builder.setRequiredNetworkType(i2);
        builder.setRequiresDeviceIdle(requirements.ˊ());
        builder.setRequiresCharging(requirements.ॱ());
        builder.setPersisted(true);
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putString("service_action", str);
        persistableBundle.putString("service_package", str2);
        persistableBundle.putInt("requirements", requirements.ˏ());
        builder.setExtras(persistableBundle);
        return builder.build();
    }

    private static void ˏ(String str) {
    }
}
